'use strict';
var clientWidgets = angular.module('clientWidgets');
var clientApp = angular.module('clientApp');

clientApp.directive('defaultWidget', ['$rootScope', 'Constant', 'Util', 'DomUtil', 'WidgetUtil',
    function($rootScope, Constant, Util, DomUtil, WidgetUtil) {

    return {
        templateUrl: '/ext/themes/flat/widget/page/default/view/main.html',
        replace: true,
        transclude: true,
        restrict: 'E',
        scope: {
            vo: '=vo',
            propMap: '=propModel'
        },
        link: function(scope, element, attrs) {
            scope.$watch('vo', function (newVal, oldVal) {

                if (newVal) {

                    var newVo = WidgetUtil.convert(scope.vo, scope.propMap);
                    scope.item = newVo;
                    $(element).height(Util.getScreenSize().h + 'px');
                    setTimeout(function() {
                        var myScroll = new IScroll($(element)[0]);
                    }, 20);
                }
            });
        }
    };
}]);

